package utils

import (
	"log"
	"os"
	"os/exec"
)

type Cmake struct {
	Path string `json:"path"`
}

func (that *Cmake) Build() {
	log.Println("cd", that.Path)
	{
		// 启动目标可执行文件
		log.Println("cmake .")
		cmd := exec.Command("cmake", ".")
		cmd.Dir = that.Path
		cmd.Stdout = os.Stdout
		if err := cmd.Run(); err != nil {
			log.Fatalln("在目录", cmd.Dir, "运行 [cmake .] 失败:", err)
		}
	}
	{
		// 启动目标可执行文件
		log.Println("cmake --build .")
		cmd := exec.Command("cmake", "--build", ".")
		cmd.Dir = that.Path
		cmd.Stdout = os.Stdout
		if err := cmd.Run(); err != nil {
			log.Fatalln("在目录", cmd.Dir, "运行 [cmake --build .] 失败:", err)
		}
	}
}
